function handleReload() {
  location.reload()
}

function msgHandler(ev) {
  switch (ev.data) {
    case 'reload':
      handleReload()
  }
}

(function () {
  console.log('hello 我是注入的脚本')
  if (!window.__WS_PORT) {
    return
  }

  const wsHost = window.__WS_HOST || location.hostname
  const wsPort = window.__WS_PORT

  const wsURL = `ws://${wsHost}:${wsPort}/`
  const ws = new WebSocket(wsURL)

  ws.addEventListener('message', msgHandler)
})()
